import Vue from "vue";
import Vuex from "vuex";
import AwesomeSwiper from 'vue-awesome-swiper'

Vue.use(Vuex);
Vue.use(AwesomeSwiper);
export default new Vuex.Store({
  state:{
      //存储的状态
      porpupStore: false,
      porpupStore1: false,
      shan:"",
      show: true,
      shopList:[]
  },
  mutations:{
      //执行的方法
      porpupFn(state){
        state.porpupStore = !state.porpupStore;
      },
      porpupFn1(state){
        state.porpupStore1 = !state.porpupStore1;
      },
      shoFn(state){
        state.show = !state.show;
      },
      addOne(state,price){
        state.totalPrice += price;
      },
      minusOne(state,price){
        state.totalPrice -= price;
      },
      addList(state,item){
              var _item = state.shopList.find(c => c.wareId === item.wareId);
              if(_item){
                  _item.number ++;
              }else{
                  state.shopList.push(item);
                  Vue.set(item,'number',1)
              }
      },
      minusList(state,item){
            var index = state.shopList.findIndex(c => c.wareId === item.wareId);
            if(state.shopList[index].number >=1){
              item.number --; 
            }
            if(state.shopList[index].number ==0){
              state.shopList.splice(index,1)
            }
      },
  },
  actions:{
    addList:function({commit},item){
        commit('addList',item) 
    },
    minusList:function({commit},item){
        commit('minusList',item)
    }
  },
  getters:{
    showList:function(state){
        return state.shopList
    }
  }
})
